﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-02-28-23:47
//  * @Description:
//  */

using UnityEngine;

namespace Code.Utility
{
    public class MoveUtils
    {
        public static Vector2 CalPositionAt(RectTransform from, RectTransform at)
        {
            //1.获取UI Camera 如果只有一个相机 就是MainCamera = Camera.main
            //将from转换到屏幕坐标
            Vector2 v2FromInScreen = RectTransformUtility.WorldToScreenPoint (Camera.main, from.transform.position);
            //将屏幕坐标转换到at的局部坐标中
            RectTransformUtility.ScreenPointToLocalPointInRectangle (at, v2FromInScreen, Camera.main, out var V2InAt);
            return new Vector2(-V2InAt.x,-V2InAt.y);
        }
        public static Vector2 CalPositionAt(Transform from, Transform at)
        {
            if (from != null) return at.position - from.position;
            return from.position;
        }
        
        
        
    }
}